/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-21 20:40:07
 * @LastEditTime: 2022-06-21 21:14:16
 * @LastEditors: liutq
 * @Reference:
 */
package aliyun

import (
	"encoding/json"
	"fmt"
	"net/http"
	"strings"
)

type Data struct {
	Result   int    `json:"result"`
	Desv     string `json:"desc"`
	Sex      string `json:"sex"`
	Birthday int    `json:"birthday"`
	Address  string `json:"address"`
}
type ParamStruct struct {
	Code   int    `json:"code"`
	TaskNo int    `json:"taskNo"`
	Data   Data   `json:"data"`
	Msg    string `json:"msg"`
}

//检查手机姓名身份证三要素
func CheckPhoneNameIdCard(phone int64, name string, idcard string) (*ParamStruct, error) {
	var appcode = " APPCODE 609ffd2d20974f2d8abcda8581718cef"

	var baseurl = "https://jmmobeck3.market.alicloudapi.com/mobile/3-validate-beckoning"

	p := fmt.Sprintf("idcard=%s&mobile=%d&name=%s", idcard, phone, name)
	jsoninfo := strings.NewReader(p)
	client := &http.Client{}
	req, err := http.NewRequest("POST", baseurl, jsoninfo)
	if err != nil {
		return nil, err
	}

	req.Header.Add("Authorization", appcode)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")

	resp, err := client.Do(req)
	fmt.Println(resp)
	if err != nil {
		fmt.Println(err.Error())
	}
	defer resp.Body.Close()

	var resp_ ParamStruct
	json.NewDecoder(resp.Body).Decode(&resp_)

	return &resp_, nil
}
